package com.ljq.ioc.core;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.HashMap;
import java.util.Map;

/**
 * 方法bean的实体类，拥有四个基本属性：
 * 1.klass：方法的返回类型
 * 2.object：方法返回的实例
 * 3.method：方法本身
 * 4.paraCount：方法的参数数
 */

public class BeanMethodDefinition {
    private Class<?> klass;
    private Object object;
    private Method method;
    private int paraCount;

    protected Class<?> getKlass() {
        return klass;
    }

    protected void setKlass(Class<?> klass) {
        this.klass = klass;
    }

    protected Object getObject() {
        return object;
    }

    protected void setObject(Object object) {
        this.object = object;
    }

    protected Method getMethod() {
        Map<Class<?>, Object> map = new HashMap<Class<?>, Object>();
        Parameter[] parameters = method.getParameters();
        for (Parameter parameter : parameters) {
            map.put(parameter.getType(), null);
        }
        paraCount = map.size();
        return method;
    }

    int decrease() {
        return --paraCount;
    }

    int getParaCount() {
        return paraCount;
    }

    protected void setMethod(Method method) {
        this.method = method;
    }

}